import type {
  GetPreOrderInfoNowParams,
  GetPreOrderInfoRes,
  OrderListParams,
  OrderListResult,
  OrderResult,
  POSTOrderParams,
} from '@/types/Order'
import { request } from '@/utils/request'

/**
 * 获取预支付订单信息
 */
export const GetPreOrderInfoAPI = () => {
  return request<GetPreOrderInfoRes>('/member/order/pre', 'GET')
}

/**
 * 立即购买订单
 */
export const GetPreOrderInfoNowAPI = (params: GetPreOrderInfoNowParams) => {
  return request<GetPreOrderInfoRes>('/member/order/pre/now', 'GET', params)
}

/**
 * 提交订单
 */
export const POSTOrderAPI = (params: POSTOrderParams) => {
  return request<{ id: string }>('/member/order', 'POST', params)
}

/**
 * 获取订单详情
 * @param id 订单id
 */
export const getMemberOrderByIdAPI = (id: string) => {
  return request<OrderResult>(`/member/order/${id}`, 'GET')
}

/**
 * 填写订单-再次购买
 * @param id 订单id
 */
export const getMemberOrderRepurchaseByIdAPI = (id: string) => {
  return request<OrderResult>(`/member/order/repurchase/${id}`, 'GET')
}

/**
 * 获取微信支付参数
 * @param data orderId 订单id
 */
export const getPayWxPayMiniPayAPI = (data: { orderId: string }) => {
  return request<WechatMiniprogram.RequestPaymentOption>('/pay/wxPay/miniPay', 'GET', data)
}

/**
 * 模拟支付-内测版
 * @param data orderId 订单id
 */
export const getPayMockAPI = (data: { orderId: string }) => {
  return request<WechatMiniprogram.RequestPaymentOption>('/pay/mock', 'GET', data)
}

/**
 * 模拟发货-内测版
 * @description 在DEV环境下使用，仅在订单状态为待发货时，可模拟发货，调用后订单状态修改为待收货，包含模拟物流。
 * @param id 订单id
 */
export const getMemberOrderConsignmentByIdAPI = (id: string) => {
  return request('/member/order/consignment', 'GET', { id })
}

/**
 * 获取订单列表
 * @param data orderState 订单状态
 */
export const getMemberOrderAPI = (params: OrderListParams) => {
  return request<OrderListResult>('/member/order', 'GET', params)
}
